package com.BigDate.server.controller;


import com.BigDate.server.pojo.Project;
import com.BigDate.server.pojo.RespBean;
import com.BigDate.server.pojo.RespPageBean;
import com.BigDate.server.service.IProjectService;
import com.BigDate.server.utils.MarkDownUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author stx
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private IProjectService projectService;

    @ApiOperation(value = "获取所有项目(分页)")
    @GetMapping("/")
    public RespPageBean getProject(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size, Project project){
        return projectService.getProjectByPage(currentPage,size,project);
    }

    @ApiOperation(value = "删除项目")
    @DeleteMapping("/{id}")
    public RespBean delProject(@PathVariable Integer id){
        if(projectService.removeById(id)){
            return RespBean.success("删除项目成功!");
        }
        return RespBean.error("删除项目失败!");
    }

    @ApiOperation(value = "获取项目内容")
    @GetMapping("/{id}")
    public String getProjectContent(@PathVariable Integer id){
        return projectService.getContent(id);
    }

    @ApiOperation(value = "获取入门类")
    @GetMapping("/findPr")
    public RespBean findPr()
    {
        return RespBean.success("获取入门类成功",projectService.findLimitPr());
    }

    @ApiOperation(value = "获取进阶类")
    @GetMapping("/findIt")
    public RespBean findIt()
    {
        return RespBean.success("获取进阶类成功",projectService.findLimitIt());
    }

    @ApiOperation(value = "获取高级类")
    @GetMapping("/findHi")
    public RespBean findHi()
    {
        return RespBean.success("获取高级类成功",projectService.findLimitHi());
    }

    @ApiOperation(value = "id查询")
    @GetMapping("/findById/{id}")
    public RespBean findById(@PathVariable("id")  Integer id){
        Project res = projectService.findById(id);
        if (res != null)
        {
            return RespBean.success("请求成功",res);
        }else{
            return RespBean.error("查询的实验不存在",null);
        }
    }

    @ApiOperation(value = "运行Python")
    @GetMapping("/run/{projectId}/{userId}")
    public void runPython(@PathVariable("projectId") Integer projectId,@PathVariable("userId")Integer userId){
        projectService.runPython(projectId,userId);
    }
}
